
#region using statements

using System;
using System.Data;
using System.Configuration;
using System.Web.UI;
//using mojoPortal.Web.Framework;
//using mojoPortal.Web.UI;
//using log4net;
//using Resources;
using System.Data.SqlClient;


#endregion

namespace mojoPortal.Web.RS.Modules
{

    public partial class RSAnnouncementControl : RSBaseUserControl  //SiteModuleControl
    {
        public mojoPortal.Business.SiteUser siteUser;

        #region OnInit

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(Page_Load);

        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetAnnouncement();
            }
        }

        private void GetAnnouncement()
        {
            mojoPortal.Business.SiteUser siteUser = mojoPortal.Web.SiteUtils.GetCurrentSiteUser();
            if (siteUser != null)
            {
                if (Session["DATATABLE_ANNOUNCEMENT"] == null)
                {
                    String strSQL = "SELECT Value, Width, CompanyID FROM rs_tblAppSetting WHERE [Key]='Announcement' AND Active=1";
                    SqlCommand myCommand;
                    SqlConnection myConnection;
                    SqlDataReader myDataReader = null;
                    myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ReadyServiceConnectionStringMain"].ToString());
                    myCommand = new SqlCommand(strSQL, myConnection);

                    myConnection.Open();
                    myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    
                    DataTable dt = new DataTable();
                    dt.Load(myDataReader);
                    Session["DATATABLE_ANNOUNCEMENT"] = dt;
                    myConnection.Close();
                }

                if (Session["DATATABLE_ANNOUNCEMENT"] != null)
                {
                    DataTable dtsession = Session["DATATABLE_ANNOUNCEMENT"] as DataTable;
                    if (dtsession.Rows.Count > 0)
                    {
                        DataRow dr = dtsession.Rows[0];
                        RSUserIdentity userIdentity = GetRSUserIdentity();
                        if (dr["CompanyID"] == DBNull.Value || int.Parse(dr["CompanyID"].ToString()) == userIdentity.RSCompanyId)
                        {
                            pnlCallout.Visible = true;
                            pnlCallout.Width = int.Parse(dr["Width"].ToString());
                            ltAnnouncement.Text = dr["Value"].ToString();
                        }
                    }
                }
            }

        }

        
    }
}
